using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Pokemon
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Card : DrawableGameComponent
    {
        private string _path;
        private string _name;
        private Texture2D _background;
        private Grid _owner;
        private Vector2 _position;
        private Vector2 _size;
        public Card(Game game, string path, Grid owner, Vector2 postition, Vector2 size)
            : base(game)
        {
            _path = path;
            _owner = owner;
            _position = postition;
            _size = size;
            Initialize();
        }

        public string Name
        {
            get { return _name; }
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            XDocument doc = XDocument.Load(_path);
            
            XName name = XName.Get(@"Name");                
            if (doc.Document != null)
            {
                var definitions = doc.Document.Descendants(name);
                _name = definitions.First().Value;
                name = XName.Get(@"Background");
                definitions = doc.Document.Descendants(name);
                string sourceBackground = definitions.First().Value;
                _background = Game.Content.Load<Texture2D>(sourceBackground);
            }
            base.Initialize();
        }
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            _owner.Owner.ScreenManager.SpriteBatch.Draw(_background, new Rectangle((int)_position.X, (int)_position.Y, (int)_size.X, (int)_size.Y), Color.White);
            base.Draw(gameTime);
        }
    }
}
